package com.cos.emp.web.interceptor;

import com.cos.emp.common.Const;
import com.cos.emp.entity.Emp;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: COS
 * @time: 2022/9/30 16:50
 * @description:
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Emp emp = (Emp) request.getSession().getAttribute(Const.IS_LOGIN);
        if (emp == null) {
            response.sendRedirect(request.getContextPath()+"/login.jsp");
            return false;
        } else {
            return true;
        }
    }
}
